<template>
  <div :data-radar-cid="cid" class="chart" />
</template>

<script>
// import 'echarts/lib/chart/radar'
// import 'echarts/lib/component/tooltip'
// import 'echarts/lib/component/title'
// import 'echarts/lib/component/legend'
// import { ChartMixin } from '../mixin'
export default {
  name: 'RadarChart',
  // mixins: [ChartMixin],
  props: {
    yData: {
      type: [String],
      required: true
    },
    cid: {
      type: [String],
      required: true
    }
  },
  data() {
    return {
      chart: null
    }
  },
  watch: {
    yData(newData) {
      console.log('sss', newData)
      this.setOptions(JSON.parse(newData))
    }
  },
  mounted() {
    this.initCharts()
  },
  methods: {
    initCharts() {
      console.log('init chart,')
      this.chart = this.$chart.init(this.$el)
      this.setOptions(JSON.parse(this.yData))
    },
    setOptions(newData) {
      this.chart.setOption({
        backgroundColor: 'rgba(204,204,204,0.7 )',
        title: {
          text: ''
        },
        tooltip: {},
        legend: {
          show: false,
          width: 200,
          right: 10,
          bottom: 10,
          orient: 'vertical',
          data: []
        },
        radar: {
        // shape: 'circle',
          name: {
            textStyle: {
              color: '#fff',
              backgroundColor: '#999',
              borderRadius: 3,
              padding: [3, 5]
            }
          },
          indicator: [
            { name: 'R型', max: 42 },
            { name: 'S型', max: 42 },
            { name: 'I型', max: 42 },
            { name: 'E型', max: 42 },
            { name: 'A型', max: 42 },
            { name: 'C型', max: 42 }
          ]
        },
        series: [{
          name: '职业兴趣测试',
          type: 'radar',
          // areaStyle: {normal: {}},
          data: [
            {
              value: newData,
              name: '职业兴趣测试',
              areaStyle: {
                normal: {
                  color: 'rgba(255,0,0,0.7)'
                }
              }
            }
          ]
        }]
      })
    }
  }
}
</script>

<style scoped>
.chart {
    margin: auto;
    width: 300px;
    height: 300px;
    background-color: white;
}
</style>
